package com.yunkaweilai.android.view.dialog.operation;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.dialog.utils.CornerUtils;
import com.flyco.dialog.widget.base.BaseDialog;
import com.github.lazylibrary.util.StringUtils;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.base.BaseApplication;
import com.yunkaweilai.android.interfaces.DialogPayInterface;
import com.yunkaweilai.android.model.PayTypeModel;
import com.yunkaweilai.android.net.Glide.GlideUtils;

/**
 * 确认付款
 * Created by Administrator on 2016/12/22 0022.
 */

public class OperationPayDialog extends BaseDialog<OperationPayDialog> {
    private TextView idTvContent;
    private TextView idTvClose;
    private TextView idTvRight;
    private String content;
    private DialogPayInterface dialogPayInterface;
    private ImageView idImgQr;
    private String type;
    private ImageView idImgTop;

    public OperationPayDialog(Context context, String content, DialogPayInterface dialogPayInterface, String type) {
        super(context);
        this.content = content;
        this.dialogPayInterface = dialogPayInterface;
        this.type = type;
    }

    @Override
    public View onCreateView() {
        widthScale(0);
        //showAnim(new Swing());
        //dismissAnim(this, new ZoomOutExit());
        View inflate = View.inflate(mContext, R.layout.dialog_operation_pay, null);
        idTvContent = ((TextView) inflate.findViewById(R.id.id_tv_content));
        idTvRight = ((TextView) inflate.findViewById(R.id.id_tv_right));
        idTvClose = (TextView) inflate.findViewById(R.id.id_tv_close);
        idImgQr = ((ImageView) inflate.findViewById(R.id.id_img_qr));
        idImgTop = ((ImageView) inflate.findViewById(R.id.id_img_top));
        initView();
        idTvContent.setText(content + "");
        //设置背景颜色，和背景的透明圆弧角度
        inflate.setBackgroundDrawable(
                CornerUtils.cornerDrawable(Color.parseColor("#f8f9fa"), dp2px(10)));

        return inflate;
    }

    private void initView() {
        PayTypeModel.DataBean.InfoBean info = BaseApplication.getPayModel().getData().getInfo();
        if ("wechat".equals(type)) {
            if ("MtoS".equals(info.getWechat_scan_pay_type()) && !StringUtils.isEmpty(info.getWechat_qr())) {
                GlideUtils.loadNoPlaceImage(mContext, info.getWechat_qr(), idImgQr);
                idImgTop.setBackgroundResource(R.mipmap.ic_wechat_top);
                idImgTop.setVisibility(View.VISIBLE);
                idImgQr.setVisibility(View.VISIBLE);
            } else {
                idImgQr.setVisibility(View.GONE);
                idImgTop.setVisibility(View.GONE);
            }
        } else if ("alipay".equals(type)) {
            if ("MtoS".equals(info.getAlipay_scan_pay_type()) && !StringUtils.isEmpty(info.getAlipay_qr())) {
                GlideUtils.loadNoPlaceImage(mContext, info.getAlipay_qr(), idImgQr);
                idImgTop.setBackgroundResource(R.mipmap.ic_alipay_top);
                idImgTop.setVisibility(View.VISIBLE);
                idImgQr.setVisibility(View.VISIBLE);
            } else {
                idImgQr.setVisibility(View.GONE);
                idImgTop.setVisibility(View.GONE);
            }
        } else {
            idImgQr.setVisibility(View.GONE);
            idImgTop.setVisibility(View.GONE);
        }


    }

    @Override
    public void setUiBeforShow() {
        idTvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogPayInterface.payMoney();
                dismiss();
            }
        });
        idTvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }


}
